import loading from '../Loading'

/**
 *  loading控制
 */
export default {
  num: 0,
  show() {
    if (!process.browser) return
    // 显示loading
    this.num += 1
    if (this.num === 1) {
      loading.show()
    }
  },
  hide() {
    if (!process.browser) return
    // 等待发出去的请求返回结果后结束loading
    if (this.num > 0) this.num -= 1
    if (this.num === 0) {
      loading.hide()
    }
  }
}
